package bil.imagem;

import java.awt.Color;
import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author Eduardo Folly
 */
public class ImagemCellRenderer extends DefaultTableCellRenderer {

    @Override
    public Component getTableCellRendererComponent(
            JTable table,
            Object value,
            boolean isSelected,
            boolean hasFocus,
            int row,
            int column) {

        Component result = super.getTableCellRendererComponent(
                table,
                value,
                isSelected,
                hasFocus,
                row,
                column);

        String status = table.getValueAt(row, 2).toString();
        if (status.equals("")) {
            result.setBackground(Color.WHITE);
        } else {
            int valor = Integer.parseInt(status);
            switch (valor) {
                case 0:
                    result.setBackground(new Color(204, 255, 204));
                    break;
                case 1:
                    result.setBackground(new Color(204, 204, 204));
                    break;
                case 2:
                    result.setBackground(new Color(255, 255, 204));
                    break;
                case 9:
                    result.setBackground(new Color(255, 151, 151));
                    break;
                default:
                    result.setBackground(Color.DARK_GRAY);
            }
        }

        if (isSelected) {
            Color back = result.getBackground().darker();
            result.setBackground(back);
        }
        return result;
    }
}
